home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / tutorials / custEducation / opengl2 / examples / irisgl_vs_opengl / quadrics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-11  |  3.5 KB  |  157 lines

  1. /*
  2.  * Copyright 1993, 1996, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17.  
  18. /* quadrics.c - demonstrates the use of the quadrics
  19.  *      Utility Library routines to draw circles and arcs.
  20.  *
  21.  *    Escape key    - exit the program
  22.  */
  23. #include <GL/gl.h>
  24. #include <GL/glu.h>
  25. #include <GL/glut.h>
  26.  
  27. #include <math.h>
  28. #include <stdio.h>
  29.  
  30. /* Function Prototypes */
  31.  
  32. GLvoid  initgfx( GLvoid );
  33. GLvoid  drawScene( GLvoid );
  34. GLvoid  reshape( GLsizei, GLsizei );
  35. GLvoid  keyboard( GLubyte, GLint, GLint );
  36.  
  37. void printHelp( char * );
  38.  
  39. /* Global Definitions */
  40.  
  41. #define KEY_ESC    27    /* ascii value for the escape key */
  42.  
  43. /* Global Variables */
  44.  
  45. static GLUquadricObj * quadObj;
  46.  
  47. void
  48. main( int argc, char *argv[] )
  49. {
  50.     GLsizei     width, height;
  51.  
  52.     glutInit( &argc, argv );
  53.  
  54.     width = glutGet( GLUT_SCREEN_WIDTH ); 
  55.     height = glutGet( GLUT_SCREEN_HEIGHT );
  56.     glutInitWindowPosition( width/4, height/4 ); 
  57.     glutInitWindowSize( width/2, height/2 );
  58.     glutInitDisplayMode( GLUT_RGBA );
  59.     glutCreateWindow( argv[0] );
  60.     
  61.     initgfx();
  62.  
  63.     glutKeyboardFunc( keyboard );
  64.     glutReshapeFunc( reshape );
  65.     glutDisplayFunc( drawScene ); 
  66.  
  67.     printHelp( argv[0] );
  68.  
  69.     glutMainLoop();
  70. }
  71.  
  72. GLvoid
  73. printHelp( char *progname )
  74. {
  75.     fprintf(stdout, "\n%s - demonstrates how to draw circles and arcs "
  76.         "using quadrics\n\n"
  77.         "Escape key        - exit the program\n\n",
  78.         progname
  79.     );
  80. }
  81.  
  82. GLvoid
  83. initgfx( GLvoid )
  84. {
  85.     glClearColor( 0.0, 0.0, 0.0, 1.0 );
  86.  
  87.     glShadeModel( GL_FLAT );
  88.  
  89.     /* Create a quadric object */
  90.     quadObj = gluNewQuadric ();
  91. }
  92.  
  93. GLvoid 
  94. keyboard( GLubyte key, GLint x, GLint y )
  95. {
  96.     switch (key) {
  97.     case KEY_ESC:    /* Exit when the Escape key is pressed */
  98.         exit(0);
  99.     }
  100. }
  101.  
  102. GLvoid
  103. reshape( GLsizei width, GLsizei height )
  104. {
  105.     GLdouble    aspect;
  106.  
  107.     glViewport( 0, 0, width, height );
  108.  
  109.     aspect = (GLdouble) width / (GLdouble) height;
  110.  
  111.     glMatrixMode( GL_PROJECTION );
  112.     glLoadIdentity();
  113.     aspect = (GLdouble) width / (GLdouble) height;
  114.     if (aspect < 1.0) 
  115.         glOrtho (0.0, 50.0, 0.0, 50.0*(1.0/aspect), -1.0, 1.0);
  116.     else 
  117.         glOrtho (0.0, 50.0*aspect, 0.0, 50.0, -1.0, 1.0);
  118.     glMatrixMode( GL_MODELVIEW );
  119.     glLoadIdentity();
  120. }
  121.  
  122. GLvoid
  123. drawScene( GLvoid )
  124. {
  125.     glClear( GL_COLOR_BUFFER_BIT );
  126.  
  127.     glPushMatrix();
  128.         gluQuadricDrawStyle (quadObj, GLU_FILL);
  129.         glColor3f (1.0, 1.0, 1.0);
  130.         glTranslatef (10.0, 10.0, 0.0);
  131.         gluDisk (quadObj, 0.0, 5.0, 10, 2);
  132.     glPopMatrix();
  133.  
  134.     glPushMatrix();
  135.         glColor3f (1.0, 1.0, 0.0);
  136.         glTranslatef (20.0, 20.0, 0.0);
  137.         gluPartialDisk (quadObj, 0.0, 5.0, 10, 3, 30.0, 120.0);
  138.     glPopMatrix();
  139.  
  140.     glPushMatrix();
  141.         gluQuadricDrawStyle (quadObj, GLU_SILHOUETTE);
  142.         glColor3f (0.0, 1.0, 1.0);
  143.         glTranslatef (30.0, 30.0, 0.0);
  144.         gluPartialDisk (quadObj, 0.0, 5.0, 10, 3, 135.0, 270.0);
  145.     glPopMatrix();
  146.  
  147.     glPushMatrix();
  148.         gluQuadricDrawStyle (quadObj, GLU_LINE);
  149.         glColor3f (1.0, 0.0, 1.0);
  150.         glTranslatef (40.0, 40.0, 0.0);
  151.         gluDisk (quadObj, 2.0, 5.0, 10, 10);
  152.     glPopMatrix();
  153.  
  154.  
  155.     glFlush();
  156. }
  157.